package server.business.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import server.business.pojo.Department;
import server.business.service.DepartmentService;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
@RequestMapping("/department")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    /**
     * 根据一级科室获取二级科室数据字典
     *
     * @return
     */
    @RequestMapping(value = "/normal/query", method = RequestMethod.GET)
    @ResponseBody
    public List<Department> getDepartmentInfo(HttpServletRequest httpServletRequest) {
        String code1 = httpServletRequest.getParameter("code1");
        List<Department> departments = departmentService.findChildByCode(code1);
        return departments;
    }

    /**
     * 查询所有一级科室
     *
     * @param
     * @return
     */
    @RequestMapping(value = "/normal/list", method = RequestMethod.GET)
    @ResponseBody
    public List<Department> selectDepartmentByCode(String code) {
        List<Department> departments = departmentService.selectDepartmentByCode(code);
        return departments;
    }
}
